# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gdbm
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.19
pkgrel=1
pkgdesc="GNU database library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.gnu.org/software/gdbm/gdbm.html"
license=('GPL3')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-libiconv")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs')
source=(https://ftp.gnu.org/gnu/gdbm/${_realname}-${pkgver}.tar.gz
        'gdbm-1.15-win32.patch')
sha256sums=('37ed12214122b972e18a0d94995039e57748191939ef74115b1d41d8811364bc'
            '2c3f0ed37482fe874218f4464414b592ebffa8776cca3c20fb0660f0036f4324')
validpgpkeys=('325F650C4C2B6AD58807327A3602B07F55D0C732')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -Np1 -i ${srcdir}/gdbm-1.15-win32.patch

  autoreconf --install --force
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-shared \
    --enable-libgdbm-compat

  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make check || true
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
